/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.base.entity.customer;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.entity.DataEntity;
import com.jeesite.common.entity.TreeEntity;
import com.jeesite.common.mybatis.annotation.Column;
import com.jeesite.common.mybatis.annotation.JoinTable;
import com.jeesite.common.mybatis.annotation.Table;
import com.jeesite.common.mybatis.mapper.query.QueryType;
import com.jeesite.modules.base.entity.guarantor.Guarantor;
import com.jeesite.modules.sys.entity.Area;
import com.jeesite.modules.sys.entity.User;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

/**
 * 客户Entity
 * @author lv
 * @version 2021-02-25
 */
@Table(name="t_customer", alias="a", columns={
		@Column(includeEntity=TreeEntity.class),
		@Column(name="customer_id", attrName="customerId", label="客户编号", isPK=true,queryType=QueryType.LIKE),
		@Column(name="customer_name", attrName="customerName", label="客户名称", queryType=QueryType.LIKE, isTreeName=true),
		@Column(name="customer_name_abbreviation", attrName="customerNameAbbreviation", label="客户名称缩写", queryType=QueryType.EQ),
		@Column(includeEntity=DataEntity.class),
		@Column(name="default_guarantor", attrName="guarantorId", label="默认担保人", isQuery=false),
		@Column(name="account_manager", attrName="accountManager", label="客户经理"),
		@Column(name="corporate_name", attrName="corporateName", label="法人姓名", isQuery=false),
		@Column(name="corporate_idcard", attrName="corporateIdcard", label="法人身份证", isQuery=false),
		@Column(name="transactor_name", attrName="transactorName", label="经办人姓名", isQuery=false),
		@Column(name="transactor_idcard", attrName="transactorIdcard", label="经办人身份证", isQuery=false),
		@Column(name="area", attrName="area.areaCode", label="区域", isQuery=false),
		@Column(name="address", attrName="address", label="详细地址", isQuery=false),
		@Column(name="taxpayer_identification_number", attrName="taxpayerIdentificationNumber", label="纳税人识别号", isQuery=false),
		@Column(name="account_name", attrName="accountName", label="户名", isQuery=false),
		@Column(name="account_number", attrName="accountNumber", label="账号", isQuery=false),
		@Column(name="bank_name_address", attrName="bankNameAddress", label="银行名称及地址", isQuery=false),
		@Column(name="data_update_date", attrName="dataUpdateDate", label="资料更新日期", isQuery=false),
		@Column(name="update_cycle", attrName="updateCycle", label="更新周期", comment="更新周期（天）", isQuery=false),
	}, joinTable = {
        @JoinTable(type = JoinTable.Type.LEFT_JOIN, entity = Area.class, alias = "b",
                on = "b.area_code = a.area",
                columns = {
                        @Column(name = "area_code", label = "区域代码", isPK = true),
                        @Column(name = "area_name", label = "区域名称", isQuery = false),
                        @Column(name = "area_type", label = "区域类型"),
                        @Column(name = "tree_names", label = "区域全称"),
                }),
        @JoinTable(type = JoinTable.Type.LEFT_JOIN, entity = Guarantor.class, attrName = "defaultGuarantor", alias = "g",
                on = "g.guarantor_id = a.default_guarantor", columns = {
                @Column(name = "guarantor_id", label = "担保人编码", isPK = true),
                @Column(name = "guarantor_name", label = "担保人名称", isQuery = false),
                @Column(name = "address", label = "现住", isQuery = false),
                @Column(name = "phone", label = "电话", isQuery = false),
                @Column(name = "id_number", label = "身份证号码", isQuery = false),
                @Column(name = "email", label = "邮箱", isQuery = false),
        }),
        @JoinTable(type = JoinTable.Type.LEFT_JOIN, entity = Customer.class, attrName = "customerpar", alias = "cuspar",
                on = "cuspar.customer_id = a.parent_code", columns = {
                @Column(name = "customer_id", label = "上级客户编码", isPK = true),
                @Column(name = "customer_name", label = "上级客户名称", isQuery = false),
        }),
        @JoinTable(type = JoinTable.Type.LEFT_JOIN, entity = User.class, attrName = "user", alias = "u",
                on = "u.user_code = a.account_manager", columns = {
                @Column(name = "user_code", label = "用户编码", isPK = true),
                @Column(name = "user_name", label = "用户名称", isQuery = false),
        }),
        @JoinTable(type = JoinTable.Type.LEFT_JOIN, entity = User.class, attrName = "createByUser", alias = "createby",
                on = "createby.user_code = a.create_by", columns = {
                @Column(name = "user_code", label = "用户编码", isPK = true),
                @Column(name = "user_name", label = "用户名称", isQuery = false),
        }),
        @JoinTable(type = JoinTable.Type.LEFT_JOIN, entity = User.class, attrName = "updateByUser", alias = "updateby",
                on = "updateby.user_code = a.update_by", columns = {
                @Column(name = "user_code", label = "用户编码", isPK = true),
                @Column(name = "user_name", label = "用户名称", isQuery = false),
        }),

}, orderBy="a.tree_sorts, a.customer_id"
)
public class Customer extends TreeEntity<Customer> {
	
	private static final long serialVersionUID = 1L;
	private Customer customerpar;
	private String customerId;		// 客户编号
	private String customerName;		// 客户名称
	private String customerNameAbbreviation;		// 客户名称缩写
	private Guarantor defaultGuarantor;		// 默认担保人
	private User user;		// 客户经理
	private String accountManager;		// 客户经理
	private String corporateName;		// 法人姓名
	private String corporateIdcard;		// 法人身份证
	private String transactorName;		// 经办人姓名
	private String transactorIdcard;		// 经办人身份证
	private Area area;		// 区域
	private String address;		// 详细地址
	private String taxpayerIdentificationNumber;		// 纳税人识别号
	private String accountName;		// 户名
	private String accountNumber;		// 账号
	private String bankNameAddress;		// 银行名称及地址
	private Date dataUpdateDate;		// 资料更新日期
	private Integer updateCycle;		// 更新周期（天）
    private String guarantorId;
	private List<CustomerShowroom> customerShowroomList = ListUtils.newArrayList();		// 子表列表
	private List<CustomerContact> customerContactList = ListUtils.newArrayList();		// 子表列表
	private List<CustomerData> customerDataList = ListUtils.newArrayList();		// 子表列表
    private User createByUser;
    private User updateByUser;


	public Customer() {
		this(null);
	}

	public Customer(String id){
		super(id);
	}

	@Override
	public Customer getParent() {
		return parent;
	}

	@Override
	public void setParent(Customer parent) {
		this.parent = parent;
	}

	public String getCustomerId() {
		return customerId;
	}

	public void setCustomerId(String customerId) {
		this.customerId = customerId;
	}
	
	@NotBlank(message="客户名称不能为空")
	@Length(min=0, max=200, message="客户名称长度不能超过 200 个字符")
	public String getCustomerName() {
		return customerName;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}
	
	@NotBlank(message="客户名称缩写不能为空")
	@Length(min=0, max=200, message="客户名称缩写长度不能超过 200 个字符")
	public String getCustomerNameAbbreviation() {
		return customerNameAbbreviation;
	}

	public void setCustomerNameAbbreviation(String customerNameAbbreviation) {
		this.customerNameAbbreviation = customerNameAbbreviation;
	}

	@NotBlank(message="法人姓名不能为空")
	@Length(min=0, max=100, message="法人姓名长度不能超过 100 个字符")
	public String getCorporateName() {
		return corporateName;
	}

	public void setCorporateName(String corporateName) {
		this.corporateName = corporateName;
	}
	
	@NotBlank(message="法人身份证不能为空")
	@Length(min=0, max=100, message="法人身份证长度不能超过 100 个字符")
	public String getCorporateIdcard() {
		return corporateIdcard;
	}

	public void setCorporateIdcard(String corporateIdcard) {
		this.corporateIdcard = corporateIdcard;
	}
	
	@NotBlank(message="经办人姓名不能为空")
	@Length(min=0, max=100, message="经办人姓名长度不能超过 100 个字符")
	public String getTransactorName() {
		return transactorName;
	}

	public void setTransactorName(String transactorName) {
		this.transactorName = transactorName;
	}
	
	@NotBlank(message="经办人身份证不能为空")
	@Length(min=0, max=100, message="经办人身份证长度不能超过 100 个字符")
	public String getTransactorIdcard() {
		return transactorIdcard;
	}

	public void setTransactorIdcard(String transactorIdcard) {
		this.transactorIdcard = transactorIdcard;
	}

	@Length(min=0, max=200, message="详细地址长度不能超过 200 个字符")
	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}
	
	@NotBlank(message="纳税人识别号不能为空")
	@Length(min=0, max=100, message="纳税人识别号长度不能超过 100 个字符")
	public String getTaxpayerIdentificationNumber() {
		return taxpayerIdentificationNumber;
	}

	public void setTaxpayerIdentificationNumber(String taxpayerIdentificationNumber) {
		this.taxpayerIdentificationNumber = taxpayerIdentificationNumber;
	}
	
	@Length(min=0, max=100, message="户名长度不能超过 100 个字符")
	public String getAccountName() {
		return accountName;
	}

	public void setAccountName(String accountName) {
		this.accountName = accountName;
	}
	
	@NotBlank(message="账号不能为空")
	@Length(min=0, max=100, message="账号长度不能超过 100 个字符")
	public String getAccountNumber() {
		return accountNumber;
	}

	public void setAccountNumber(String accountNumber) {
		this.accountNumber = accountNumber;
	}
	
	@Length(min=0, max=200, message="银行名称及地址长度不能超过 200 个字符")
	public String getBankNameAddress() {
		return bankNameAddress;
	}

	public void setBankNameAddress(String bankNameAddress) {
		this.bankNameAddress = bankNameAddress;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd")
	@NotNull(message="资料更新日期不能为空")
	public Date getDataUpdateDate() {
		return dataUpdateDate;
	}

	public void setDataUpdateDate(Date dataUpdateDate) {
		this.dataUpdateDate = dataUpdateDate;
	}
	
	@NotNull(message="更新周期不能为空")
	public Integer getUpdateCycle() {
		return updateCycle;
	}

	public void setUpdateCycle(Integer updateCycle) {
		this.updateCycle = updateCycle;
	}
	
	public List<CustomerShowroom> getCustomerShowroomList() {
		return customerShowroomList;
	}

	public void setCustomerShowroomList(List<CustomerShowroom> customerShowroomList) {
		this.customerShowroomList = customerShowroomList;
	}
	
	public List<CustomerContact> getCustomerContactList() {
		return customerContactList;
	}

	public void setCustomerContactList(List<CustomerContact> customerContactList) {
		this.customerContactList = customerContactList;
	}
	
	public List<CustomerData> getCustomerDataList() {
		return customerDataList;
	}

	public void setCustomerDataList(List<CustomerData> customerDataList) {
		this.customerDataList = customerDataList;
	}

    public Customer getCustomerpar() {
        return customerpar;
    }

    public void setCustomerpar(Customer customerpar) {
        this.customerpar = customerpar;
    }

    public Area getArea() {
        return area;
    }

    public void setArea(Area area) {
        this.area = area;
    }

    public Guarantor getDefaultGuarantor() {
        return defaultGuarantor;
    }

    public void setDefaultGuarantor(Guarantor defaultGuarantor) {
        this.defaultGuarantor = defaultGuarantor;
    }

    public String getGuarantorId() {
        return guarantorId;
    }

    public void setGuarantorId(String guarantorId) {
        this.guarantorId = guarantorId;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String getAccountManager() {
        return accountManager;
    }

    public void setAccountManager(String accountManager) {
        this.accountManager = accountManager;
    }

    public User getCreateByUser() {
        return createByUser;
    }

    public void setCreateByUser(User createByUser) {
        this.createByUser = createByUser;
    }

    public User getUpdateByUser() {
        return updateByUser;
    }

    public void setUpdateByUser(User updateByUser) {
        this.updateByUser = updateByUser;
    }
}